|
|
|
|
|
|
|
Next, add a command button to the form. Change its Name property to cmdCalculate and its Caption property to Calculate Job Cost. Enter the lines of code in Listing 9.1 into the command button's Click event procedure. Save and run the program to see it in action. |
|
|
|
|
| |
|
|
|
|
This example is available on the Que Web site at www.quebooks.com. |
|
|
|
|
|
|
|
|
|
|
Exponents are also known as powers of a number. For example, 2 raised to the third power (23) is equivalent to 2×2×2, or 8. Exponents are used quite a lot in computer operations, where many things are represented as powers of two. Exponents are also used extensively in scientific and engineering work, where mathematical terms are often represented as powers of 10 or as natural logarithms. Simpler exponents are used in statistics, where many calculations depend on the squares and the square roots of numbers. |
|
|
|
|
|
|
|
|
To raise a number to a power, you use the exponential operator, which is a caret (^). Exponents greater than one indicate a number raised to a power. Fractional exponents indicate a root, and negative exponents indicate a fraction. The following is the syntax for using the exponential operator: |
|
|
|
|
|
|
|
|
answer = number1 ^ exponent |
|
|
|
|
|
|
|
|
The equations in the following table show several common uses of exponents. The operation performed by each equation is also indicated. |
|
|
|
|
| | | |
|
|
|
|
This is the square of the number. |
|
|
|
| | |
|
|
|
|
This is the square root of the number. |
|
|
|
| | |
|
|
|
|
A fraction is obtained by using a negative exponent. |
|
|
|
|
|
|
|
|
|
|
Many expressions contain some combination of the operators just discussed. In such cases, knowing in what order Visual Basic processes the various types of operators is important. For example, what's the value of the expression 4 * 3 + 6 / 2? You might think that the calculations would be performed from left to right. In this case, 4 * 3 is 12; 12 + 6 is 18; 18 / 2 is 9. However, Visual Basic doesn't necessarily process expressions straight through from left to right. It follows a distinct order of processing known as operator precedence. |
|
|
|
|
|
|
|
|
Simply put, Visual Basic performs subsets of a complex expression according to the operators involved, in this order: |
|
|
|
|
|
|
|
|
Multiplication and division (*, /) |
|
|
|
|
|